<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body {
            background: #000;
        }
        #canvas {
            background: #fff;
        }
    </style>
</head>
<body>
    <video src="./movie.ogg" autoplay id="video" loop></video>
    <canvas id="canvas" width="320" height="240"></canvas>


    <script type="text/javascript">
        let canvas = document.querySelector('#canvas');
        let video = document.querySelector('#video');
        let ctx = canvas.getContext('2d');

        ctx.drawImage(video, 0, 0);

        function next() {
            ctx.drawImage(video, 0, 0);
            let imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
            let w = imageData.width;
            let h = imageData.height;
            for (let i = 0; i < h; i++) {
                for (let j = 0; j < w; j++) {
                    imageData.data[(i * w + j) * 4 + 0] = imageData.data[(i * w + j) * 4 + 1] = imageData.data[(i * w + j) * 4 + 2] = (imageData.data[(i * w + j) * 4 + 0] + imageData.data[(i * w + j) * 4 + 1] + imageData.data[(i * w + j) * 4 + 2]) / 3;
                }
            }
            ctx.putImageData(imageData, 0, 0);
            requestAnimationFrame(next);
        }

        requestAnimationFrame(next);

    </script>
</body>
</html>
